﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace PasswordProvider.ViewModel.Framework
{
    /// <summary>
    /// EnumSelectorViewModel: Encapsulates the data and business rules for editing an enumerated type.
    /// Inherits from VisualViewModel and adds properties EnumValue (enum) and EnumDisplayEntries (List of EnumDisplayEntries)
    /// </summary>
    public class EnumSelectorViewModel : VisualViewModel
    {
        internal event ValueChangedEventHandler<Enum> EnumValueChanged;

        private Enum _originalValue;

        internal EnumSelectorViewModel(string displayString, string toolTip, Enum enumValue)
            : base(displayString, toolTip)
        {
            _enumValue = enumValue;
            _originalValue = enumValue;
        }

        public override bool IsChanged
        {
            get
            {
                return (EnumValue.CompareTo(_originalValue) != 0);
            }
        }

        /// <summary>
        /// Value;
        /// </summary>
        public Enum EnumValue
        {
            get { return _enumValue; }
            set 
            {
                if (base.SetPropertyValue(value, ref _enumValue, "EnumValue"))
                {
                    if (EnumValueChanged != null)
                        EnumValueChanged(_enumValue);
                }
            }

        } Enum _enumValue;
        
        /// <summary>
        /// Enum display entries for the enum selector display value overrides.
        /// </summary>
        public Collection<EnumSelectorDisplayItemViewModel> DisplayItems
        {
            get
            {
                if (_enumDisplayItems == null)
                {
                    _enumDisplayItems = new Collection<EnumSelectorDisplayItemViewModel>();
                }
                return _enumDisplayItems;
            }
        } private Collection<EnumSelectorDisplayItemViewModel> _enumDisplayItems;

    }

    /// <summary>
    /// Holds data for an EnumSelectorDisplayItem object instance.
    /// </summary>
    public class EnumSelectorDisplayItemViewModel : VisualViewModel
    {
        internal EnumSelectorDisplayItemViewModel(string displayName, string toolTip, Enum enumValue)
            : base(displayName, toolTip)
        {
            EnumValue = enumValue;
        }
        public Enum EnumValue
        {
            get
            {
                return _value;
            }
            set { SetPropertyValue(value, ref _value, "EnumValue"); }
        } private Enum _value;
    }

}
